//
//  AppDelegate.m
//  LT
//
//  Created by dllo on 16/5/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "RecommendViewController.h"
#import "DestinationViewController.h"
#import "communityViewController.h"
#import "UserViewController.h"
#import "ViewController.h"

#import "UMSocialWechatHandler.h"

//#define LAST_RUN_VERSION_KEY  @"last_run_version_of_application"

//添加导航页需要引的头文件1
#import "ViewController.h"

@interface AppDelegate ()


//啦啦啦


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //准备window
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    //***********添加友盟
    [UMSocialData setAppKey:@"558936d367e58eb81b001298"];
    
    [[DataBaseHandle shareDataBaseHandle] zhuanTOpenDB];
    [[DataBaseHandle shareDataBaseHandle] ZhuanTCreatTable];
    
    //==========================把每个界面的视图添加进tabBar
    //一 : "推荐"界面视图控制器
    RecommendViewController *recommendVC = [[RecommendViewController alloc]init];
    UINavigationController *recommendNa = [[UINavigationController alloc]initWithRootViewController:recommendVC];
    //设置"推荐"视图的tag值,和tabBar
    recommendNa.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"推荐" image:[UIImage imageNamed:@"recommend"] tag:101];
    
    //二 : "目的地界面视图控制器"
    DestinationViewController *destinationVC = [[DestinationViewController alloc]init];
    UINavigationController *destinationNa = [[UINavigationController alloc]initWithRootViewController:destinationVC];
    destinationNa.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"目的地" image:[UIImage imageNamed:@"destination"] tag:102];
    
    //三 : "社区界面"视图控制器
   communityViewController *communityVC = [[communityViewController alloc]init];
    UINavigationController *communityNa = [[UINavigationController alloc]initWithRootViewController:communityVC];
    communityNa.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"社区" image:[UIImage imageNamed:@"community"] tag:103];
    //四: "我的"界面视图控制器
    UserViewController *userVC = [[UserViewController alloc]init];
    UINavigationController *userNa = [[UINavigationController alloc]initWithRootViewController:userVC];
    userNa.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"user"] tag:104];
    
    //=================================将tabBar设置为跟视图控制器
    UITabBarController *tabBar = [[UITabBarController alloc]init];
    self.window.rootViewController = tabBar;
    //吧四个界面添加到tabBar的控制器中
    tabBar.viewControllers = @[recommendNa,destinationNa,communityNa,userNa];
    //=============================================
    
    

    
  //***************判断是否是第一次登陆
    NSUserDefaults *FirstLanuch = [NSUserDefaults standardUserDefaults];
    NSString *key = [NSString stringWithFormat:@"is_first"];
    NSString *value = [FirstLanuch objectForKey:key];
    
    if (!value) {
        NSUserDefaults *setting = [NSUserDefaults standardUserDefaults];
        
        NSString *key = [NSString stringWithFormat:@"is_first"];
        
        [setting setObject:[NSString stringWithFormat:@"false"] forKey:key];
        [setting synchronize];
        
        ViewController *vc = [[ViewController alloc] init];
        //吧window里的tabBar传到viewController
        vc.tabBar = tabBar;
        UINavigationController *Na = [[UINavigationController alloc]initWithRootViewController:vc];
        self.window.rootViewController = Na;
    }else{
    
        NSLog(@"已经不是第一次启动了");
        //如果不是第一次启动的话,使用RecommendViewController作为根视图
        self.window.rootViewController = tabBar;
    
    }
    
    
    
    
    
    return YES;
}





- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
